//
//  WPTradeTableViewCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/5.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTradeListTableViewCell.h"

@interface WPTradeListTableViewCell ()
@property (nonatomic, strong) UIImageView * headImageView;/**< 头像 */
@property (nonatomic, strong) UIImageView * littleImageView;/**< 实名制小图标 */
@property (nonatomic, strong) UILabel * nameLabel;/**< 名字文本 */
@property (nonatomic, strong) UILabel * typeLabel;/**< 类型说明文本 */
@property (nonatomic, strong) UILabel * positionTitleLabel;/**< 位置标题 */
@property (nonatomic, strong) UILabel * positionLabel;/**< 具体位置文本 */
@property (nonatomic, strong) UIView * line;/**< 分割线 */
@property (nonatomic, strong) UITextField * priceTextField;/**< 价格文本 */
@property (nonatomic, strong) UIButton * positionBtn;/**< 查看位置按钮 */
@property (nonatomic, strong) UIButton * buyBtn;/**< 购票按钮 */
- (void)initializeAppearance;/**< 一般界面初始化 */


@end
@implementation WPTradeListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initializeAppearance];
    }
    return self;
}
- (void)initializeAppearance {
    self.backgroundColor = COLOR_RGB(60, 52, 52, 1);
    [self addSubview:self.headImageView];
    [self addSubview:self.littleImageView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.typeLabel];
    [self addSubview:self.positionTitleLabel];
    [self addSubview:self.positionLabel];
    [self addSubview:self.line];
    [self addSubview:self.priceTextField];
    [self addSubview:self.positionBtn];
    [self addSubview:self.buyBtn];
}
#pragma mark - responds events
- (void)actionOnPositionBtn {
    if (self.delegate && [_delegate respondsToSelector:@selector(respondsToPositionBtn)]) {
        [_delegate respondsToPositionBtn];
    }
}
- (void)actionOnBuyBtn {
    if (self.delegate && [_delegate respondsToSelector:@selector(respondsToBuyBtnWithRightTransModel:)]) {
        [_delegate respondsToBuyBtnWithRightTransModel:_model];
    }
}
- (void)setModel:(WPRightTransModel *)model {
    _model = model;
    _headImageView.image = IMAGE_NAME(@"列表头像");
    if (model.salePersonName.length == 11) {
        _nameLabel.text = [NSString stringWithFormat:@"%@****%@", [model.salePersonName substringToIndex:3], [model.salePersonName substringWithRange:NSMakeRange(7, 4)]];
    } else {
        _nameLabel.text = model.salePersonName;
    }
    if ([model.saleType isEqualToString:@"SINGLE"]) {
        _typeLabel.text = @"单人票";
    }
    if ([model.saleType isEqualToString:@"PAIR"]) {
        _typeLabel.text = @"情侣票";
    }
    if ([model.saleType isEqualToString:@"COMBINATION"]) {
        _typeLabel.text = @"组合票";
    }
    _positionLabel.text = model.ticketName;
    _priceTextField.text = [NSString stringWithFormat:@"¥ %.2f", [model.salePrice floatValue]];
//    _positionTextView.frame = CGRectMake(CGRectGetMaxX(self.positionTitleLabel.frame), CGRectGetMinY(self.typeLabel.frame), 203*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier());
//    _positionLabel.text = model.position;
}
#pragma mark - getter
- (UIImageView *)headImageView {
    if (!_headImageView) {
        _headImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(12*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier(), 36*DHFlexibleHorizontalMutiplier(), 36*DHFlexibleHorizontalMutiplier())];
            view.layer.cornerRadius = 18*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view.layer.borderWidth = 1;
            view.layer.borderColor = COLOR_RGB(85, 85, 85, 1).CGColor;
            view;
        });
    }
    return _headImageView;
}
- (UIImageView *)littleImageView {
    if (!_littleImageView) {
        _littleImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+10*DHFlexibleHorizontalMutiplier(), 35*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier())];
            view;
        });
    }
    return _littleImageView;
}
- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.typeLabel.frame)+15*DHFlexibleHorizontalMutiplier(), CGRectGetMidY(self.headImageView.frame)-15*DHFlexibleHorizontalMutiplier(), 200, 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.textColor = [UIColor whiteColor];
            lab;
        });
    }
    return _nameLabel;
}
- (UILabel *)typeLabel {
    if (!_typeLabel) {
        _typeLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(12*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.headImageView.frame)+10*DHFlexibleHorizontalMutiplier(), 36*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            lab.backgroundColor = COLOR_RGB(85, 85, 85, 1);
            lab.textColor = COLOR_RGB(172, 172, 172, 1);
            lab.layer.cornerRadius = 3*DHFlexibleHorizontalMutiplier();
            lab.layer.masksToBounds = YES;
            lab.font = [UIFont systemFontOfSize:8.5*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            lab;
        });
    }
    return _typeLabel;
}
- (UILabel *)positionTitleLabel {
    if (!_positionTitleLabel) {
        _positionTitleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.nameLabel.frame), CGRectGetMinY(self.typeLabel.frame), 30*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(171, 171, 171, 1);
            lab.text = @"票位：";
            lab;
        });
    }
    return _positionTitleLabel;
}
- (UILabel *)positionLabel {
    if (!_positionLabel) {
        _positionLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.positionTitleLabel.frame), CGRectGetMinY(self.typeLabel.frame), 203*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier())];
            lab.textColor = [UIColor whiteColor];
            lab.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            lab.numberOfLines = 0;
            lab.text = @"A区1排25号";
            lab;
        });
    }
    return _positionLabel;
}
- (UIView *)line {
    if (!_line) {
        _line = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.positionLabel.frame)+10*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 0.5)];
            view.backgroundColor = COLOR_RGB(68, 60, 60, 1);
            view;
        });
    }
    return _line;
}
- (UITextField *)priceTextField {
    if (!_priceTextField) {
        _priceTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.headImageView.frame), CGRectGetMaxY(self.typeLabel.frame) + 20*DHFlexibleHorizontalMutiplier(), 200, 25*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 30*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(171, 171, 171, 1);
            lab.text = @"票价：";
            text.leftView = lab;
            text.textColor = [UIColor whiteColor];
            text.font = [UIFont systemFontOfSize:18*DHFlexibleHorizontalMutiplier()];
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _priceTextField;
}
- (UIButton *)positionBtn {
    if (!_positionBtn) {
        _positionBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(290*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier());
            [btn setImage:IMAGE_NAME(@"zwan") forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(actionOnPositionBtn) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _positionBtn;
}
- (UIButton *)buyBtn {
    if (!_buyBtn) {
        _buyBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(235*DHFlexibleHorizontalMutiplier(), CGRectGetMinY(self.priceTextField.frame), 75*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier());
            btn.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            btn.layer.cornerRadius = 3*DHFlexibleHorizontalMutiplier();
            [btn setTitle:@"立即抢购" forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(actionOnBuyBtn) forControlEvents:UIControlEventTouchUpInside];
            btn;

        });
    }
    return _buyBtn;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
